package com.whstudio.task;

import java.sql.Date;
import java.sql.SQLException;

import com.whstudio.util.mvc.action.ActionUtil;
import com.whstudio.util.mvc.bo.AbstractBO;
import com.whstudio.util.xml.IDocument;

/**
 * 任务管理业务逻辑类
 * @author wgp
 *
 */
public class TaskBO extends AbstractBO{
	private TaskDAO dao=new TaskDAO();
	/**
	 * 新增原始任务信息
	 * @param executeDate
	 * @param taskContent
	 * @return
	 * @throws SQLException
	 */
	public IDocument doAddOriginalTask(IDocument document){
		String taskName=document.getRootAttr("task_name");
		String dateString=document.getRootAttr("execute_date");
		String taskContent=document.getDocumentElement().getTextContent();
		Date executeDate=Date.valueOf(dateString);
		try {
			Integer taskIdInteger=dao.insertOriginalTask(taskName,executeDate, taskContent);
			dao.insertIntoReviewTask(taskIdInteger, executeDate);
		} catch (SQLException e) {
			ActionUtil.getErrorDoc(e.getMessage());
		}
		return ActionUtil.getPromptDoc("1", "");
	}
	
	/**
	 * 查询所有原始任务信息
	 * @param document
	 * @return
	 */
	public IDocument doQueryAllOriginalTask(IDocument document){
		try {
			return dao.queryAllOriginalTasks();
		} catch (SQLException e) {
			return ActionUtil.getErrorDoc(e.getMessage());
		}
	}
	
	/**
	 * 查询当天原始任务信息
	 * @param document
	 * @return
	 */
	public IDocument doQueryTodayOriginalTask(IDocument document){
		try {
			return dao.queryTodayTasks();
		} catch (SQLException e) {
			return ActionUtil.getErrorDoc(e.getMessage());
		}
	}
	
	/**
	 * 查询当天复习任务信息
	 * @param document
	 * @return
	 */
	public IDocument doQueryTodayReviewTask(IDocument document){
		try {
			return dao.queryTodayReviewTasks();
		} catch (SQLException e) {
			return ActionUtil.getErrorDoc(e.getMessage());
		}
	}
	
	/**
	 * 查询今天的日期
	 * @param document
	 * @return
	 */
	public IDocument doQueryTodayDate(IDocument document){
		try {
			String today=dao.getNowDate().toString();
			return ActionUtil.getPromptDoc("1", today);
		} catch (SQLException e) {
			return ActionUtil.getErrorDoc(e.getMessage());
		}
	}
	
}
